﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section header{

}

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form" action="" lay-filter="example" style="margin-top: 30px;">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">任务名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">任务类型</label>
                        <div class="layui-input-inline">
                            <select name="jobType" lay-verify="required">
                                <option value="" selected="">请选择</option>
                                <option value="1">一般任务</option>
                                <option value="2">Api任务</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" name="status" lay-skin="switch" lay-text="启用|禁用" value="1">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">完整地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="jobFullName" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">cron表达式</label>
                        <div class="layui-input-inline">
                            <input type="text" name="cronExpression" lay-verify="required" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">运行超时秒数</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="runTimeoutSeconds" lay-verify="required|number" autocomplete="off" value="0">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">参数信息</label>
                    <div class="layui-input-block">
                        <textarea class="layui-textarea" name="parameters" placeholder="JSON字符串"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea class="layui-textarea" name="remark"></textarea>
                    </div>
                </div>
                <div class="layui-form-item" style="text-align: center;">
                    <button class="layui-btn" lay-submit="" lay-filter="save">保存</button>
                    <button type="button" class="layui-btn layui-btn-primary" function="close">关闭</button>
                </div>
            </form>
        </div>
    </div>
</body>


<script>
        layui.use(['form'], function () {
            var form = layui.form;

            $("[function='close']").click(function () {
                common.closeOpen();
            });


            form.on('submit(save)', function (data) {
                if (data.field.status != "1") {
                    data.field.status = 2;
                }

                var promptLayer = common.reloadMsg("正在保存");
                request.ajax({
                    type: "post",
                    url: "/Schedule/Insert",
                    data: data.field,
                    success: function (result) {
                        common.closeMsg(promptLayer);
                        if (result.success) {
                            $('#isReload', window.parent.document).val("1");
                            common.closeOpen();
                        }
                        else {
                            common.errorMsg(result.message);
                        }
                    }
                });

                return false;
            });
        });
</script>